package com.hrt.datasender.datadao.service;

import java.util.List;

import com.btcode.db.sqlparameter.SQLParameterList;
import com.btcode.orm.executer.IORMExecuter;
import com.hrt.datasender.datadao.model.BcSendPlatformDataStrategyModel;
import com.hrt.db.DBManager;

public final class BcSendPlatformDataStrategyService {

    private static volatile BcSendPlatformDataStrategyService instance;

    private BcSendPlatformDataStrategyService() {

    }

    public static BcSendPlatformDataStrategyService getInstance() {
        if (instance == null) {
            synchronized (BcSendPlatformDataStrategyService.class) {
                if (instance == null) {
                    instance = new BcSendPlatformDataStrategyService();
                }
            }
        }
        return instance;
    }

    public void create(BcSendPlatformDataStrategyModel model) {
        IORMExecuter executer = DBManager.getORMExecuter();
        executer.create(model);
    }

    public void update(BcSendPlatformDataStrategyModel model) {
        IORMExecuter executer = DBManager.getORMExecuter();
        executer.update(model);
    }

    public void delete(String id) {
        BcSendPlatformDataStrategyModel model = new BcSendPlatformDataStrategyModel();
        model.setId(id);
        BcDeviceMonitorParamService.getInstance().deleteByDevice(id);
        DBManager.getORMExecuter().delete(model);
    }

    public BcSendPlatformDataStrategyModel getModel(String id) {
        BcSendPlatformDataStrategyModel model = new BcSendPlatformDataStrategyModel();
        model.setId(id);
        model = DBManager.getORMExecuter().getModel(model);
        return model;
    }

    public List<BcSendPlatformDataStrategyModel> getList(String platformId) {

        String sql = " SELECT * FROM BC_SEND_PLATFORM_DATA_STRATEGY WHERE PLATFORM_ID = @platformId ";

        SQLParameterList pc = new SQLParameterList();
        pc.put("platformId", platformId);

        List<BcSendPlatformDataStrategyModel> result = DBManager.getORMExecuter().getModelListSQL(sql, pc,
                BcSendPlatformDataStrategyModel.class);

        return result;
    }

    public List<BcSendPlatformDataStrategyModel> getModels(BcSendPlatformDataStrategyModel model) {
        return DBManager.getORMExecuter().getModels(model);
    }

}